//
//  XNStatusToolBar.swift
//  weibo
//
//  Created by 王向宁 on 16/5/25.
//  Copyright © 2016年 王向宁. All rights reserved.
//微博底部工具条

import UIKit

class XNStatusToolBar: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setUpUI()
        
        backgroundColor = UIColor(white: 0.95, alpha: 1.0)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setUpUI() {
        addChildBtn(repostBtn, title: "转发", imageName: "timeline_icon_retweet")
        
        addChildBtn(commentBtn, title: "评论", imageName: "timeline_icon_comment")
        
        addChildBtn(ohYeahBtn, title: "赞", imageName: "timeline_icon_like")
        
        repostBtn.snp_makeConstraints { (make) in
            make.left.top.bottom.equalTo(self)
        }
        
        commentBtn.snp_makeConstraints { (make) in
            make.left.equalTo(repostBtn.snp_right)
            
            make.top.bottom.equalTo(repostBtn)
            
            make.width.equalTo(repostBtn.snp_width)
        }
        
        ohYeahBtn.snp_makeConstraints { (make) in
            make.left.equalTo(commentBtn.snp_right)
            
            make.top.bottom.equalTo(commentBtn)
            
            make.right.equalTo(self)
            
            make.width.equalTo(repostBtn.snp_width)
        }
        
        //添加分隔线
        let sepView1 = lineView()
        
        let sepView2 = lineView()
        
        addSubview(sepView1)
        
        addSubview(sepView2)
        
        let width = 1 / UIScreen.mainScreen().scale
        
        sepView1.snp_makeConstraints { (make) in
            make.right.equalTo(commentBtn.snp_left)
            
            make.centerY.equalTo(self.snp_centerY)
            
            make.height.equalTo(self.snp_height).multipliedBy(0.4)
            
            make.width.equalTo(width)
        }
        
        sepView2.snp_makeConstraints { (make) in
            make.left.equalTo(commentBtn.snp_right)
            
            make.centerY.equalTo(self.snp_centerY)
            
            make.height.equalTo(self.snp_height).multipliedBy(0.4)
            
            make.width.equalTo(width)
        }

    }
    
    private func lineView() -> UIView {
        let line = UIView()
        
        line.backgroundColor = UIColor.purpleColor()
        
        return line
        
    }
    
    private func addChildBtn(btn: UIButton,title: String,imageName: String) {
        btn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        
        btn.setTitle(title, forState: .Normal)
        
        btn.titleLabel?.font = UIFont.systemFontOfSize(10)
        
        btn.setImage(UIImage(named: imageName), forState: .Normal)
        
        btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: .Normal)
        
        btn.sizeToFit()
        
        self.addSubview(btn)
        
    }
    
    //懒加载控件
    private lazy var repostBtn: UIButton = UIButton()
    
    private lazy var commentBtn: UIButton = UIButton()
    
    private lazy var ohYeahBtn: UIButton = UIButton()

}
